package com.jiang.daily.Q2931;

import java.util.Arrays;

/**
 * @author Jiang
 * @version 1.0
 * @date 2024/12/12 13:06
 */
class Solution {
    public long maxSpending(int[][] values) {
        // 拉伸排序
        int num = values.length * values[0].length;
        int[] arr = new int[num];
        int index = 0;
        for(int[] value: values) {
            for(int v: value) {
                arr[index++] = v;
            }
        }
        Arrays.sort(arr);
        long res = 0;
        for (int i = 0; i < num; i++) {
            res += 1L * arr[i] * (i + 1);
        }
        return res;
    }
}
